package org.rslai.tcedit.domain;

import java.sql.Clob;
import javax.persistence.*;
import org.hibernate.validator.*;
import org.rslai.tcedit.util.StrUtil;

/**
 * 角色信息
 * 
 * @author rslai
 */
@Entity
@Table(name="t_role")
public class Role extends UUIDSupport {
	private String name = "ROLE_"; // 角色名
	private String describing; // 角色描述
	private Clob urlPermission; // 权限
	private String urlPermissionStr = ""; // 权限字符串
	private Clob methodPermission; // 权限
	private String methodPermissionStr = ""; // 权限字符串
	private Boolean bonding = false; // 邦定到产品

	@Column(nullable = false, length = 20)
	@Pattern(regex = "ROLE_[a-zA-Z0-9_]{0,20}", message = "角色名必须以 ROLE_ 开头且只能由英文字母和数字构成，长度请限制在20个字以内")
	public String getName() { return name; }
	public void setName(String name) { this.name = name; }

	@Column(nullable = false, length = 30)
	@Length(max = 30, message = "角色描述请限制在30个字以内")
	public String getDescribing() { return describing; }
	public void setDescribing(String describing) { this.describing = describing; }

	@Column(nullable = true)
	public Clob getUrlPermission() { return urlPermission; }
	public void setUrlPermission(Clob urlPermission) {
		this.urlPermission = urlPermission;
		this.urlPermissionStr = StrUtil.toString(urlPermission);
	}

	@Column(nullable = true)
	public Clob getMethodPermission() { return methodPermission; }
	public void setMethodPermission(Clob methodPermission) {
		this.methodPermission = methodPermission;
		this.methodPermissionStr = StrUtil.toString(methodPermission);
	}

	@Column(nullable = false)
	public Boolean getBonding() { return bonding; }
	public void setBonding(Boolean bonding) { this.bonding = bonding; }

	/**
	 * 得到Url权限列表
	 * @return 返回字符数组
	 */
	@Transient
	public String[] getUrlPermissionStrList() {
		return StrUtil.split(urlPermissionStr);
	}

	/**
	 * 返回Url权限字符串
	 * @return
	 */
	@Transient
	public String getUrlPermissionStr() {
		return urlPermissionStr;
	}

	/**
	 * 设置Url权限字符串
	 * @return
	 */
	@Transient
	public void setUrlPermissionStr(String urlPermissionStr) {
		this.urlPermissionStr = urlPermissionStr;
		this.urlPermission = StrUtil.toClob(urlPermissionStr);
	}

	/**
	 * 得到Method权限列表
	 * @return 返回字符数组
	 */
	@Transient
	public String[] getMethodPermissionStrList() {
		return StrUtil.split(methodPermissionStr);
	}

	/**
	 * 返回Method权限字符串
	 * @return
	 */
	@Transient
	public String getMethodPermissionStr() {
		return methodPermissionStr;
	}
	/**
	 * 设置Method权限字符串
	 * @return
	 */
	@Transient
	public void setMethodPermissionStr(String methodPermissionStr) {
		this.methodPermissionStr = methodPermissionStr;
		this.methodPermission = StrUtil.toClob(methodPermissionStr);
	}

}
